#include "Screen.h"
#include "cData.h"


Screen::Screen()
{
}


Screen::~Screen()
{
}

bool Screen::LoadScreen()
{
	bool res;

	res = true;

	//Load Mainmenu
	
	
	m_id_DL1 = glGenLists(1);
	glNewList(m_id_DL1, GL_COMPILE);
		glBegin(GL_QUADS);
		glTexCoord2f(	0, 1	);				glVertex2i	(	0		,		0		);
		glTexCoord2f(	1, 1	);				glVertex2i	(	800		,		0		);
		glTexCoord2f(	1, 0	);				glVertex2i	(	800		,		600		);
		glTexCoord2f(	0, 0	);				glVertex2i	(	0		,		600		);
		glEnd();
	glEndList();

	
	//Load RoomControls

	m_id_DL2 = glGenLists(1);
	glNewList(m_id_DL2, GL_COMPILE);
		glBegin(GL_QUADS);
		glTexCoord2f(	0, 1	);				glVertex2i	(	0		,		0		);
		glTexCoord2f(	1, 1	);				glVertex2i	(	800		,		0		);
		glTexCoord2f(	1, 0	);				glVertex2i	(	800		,		600		);
		glTexCoord2f(	0, 0	);				glVertex2i	(	0		,		600		);
		glEnd();
	glEndList();

	//Load RoomScores

	m_id_DL3 = glGenLists(1);
	glNewList(m_id_DL3, GL_COMPILE);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 1);				glVertex2i(0, 0);
		glTexCoord2f(1, 1);				glVertex2i(800, 0);
		glTexCoord2f(1, 0);				glVertex2i(800, 608);
		glTexCoord2f(0, 0);				glVertex2i(0, 608);
		glEnd();
	glEndList();

	//Load RoomCredits

	

	m_id_DL4 = glGenLists(1);
	glNewList(m_id_DL4, GL_COMPILE);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 1);				glVertex2i(0, 0);
		glTexCoord2f(1, 1);				glVertex2i(800, 0);
		glTexCoord2f(1, 0);				glVertex2i(800, 608);
		glTexCoord2f(0, 0);				glVertex2i(0, 608);
		glEnd();
	glEndList();


	/*m_start.LoadButton(m_instart, "play.png");
	m_controls.LoadButton(m_incontrols, "controls.png");
	m_scores.LoadButton(m_inscores, "scores.png");
	m_credits.LoadButton(m_incredits, "credits.png");
	m_back.LoadButton(m_inback, "back.png");*/
	
	return res;
}



void Screen::Draw(int * screentex_id, int * buttonsTex_ids, int screen)
{
	if (screen == 1)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, screentex_id[0]);
		glCallList(m_id_DL1);
		glDisable(GL_TEXTURE_2D);

		m_start.DrawButton(m_instart, "play.png", buttonsTex_ids[0]);
		m_controls.DrawButton(m_incontrols, "controls.png", buttonsTex_ids[1]);
		m_scores.DrawButton(m_inscores, "scores.png", buttonsTex_ids[2]);
		m_credits.DrawButton(m_incredits, "credits.png",buttonsTex_ids[3]);
	}
	else if (screen == 2)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, screentex_id[1]);
		glCallList(m_id_DL2);
		glDisable(GL_TEXTURE_2D);
		m_back.DrawButton(m_inback, "back.png", buttonsTex_ids[4]);
	}
	else if (screen == 3)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, screentex_id[2]);
		glCallList(m_id_DL3);
		glDisable(GL_TEXTURE_2D);
		m_back.DrawButton(m_inback, "back.png", buttonsTex_ids[4]);
	}
	else if (screen == 4)
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, screentex_id[3]);
		glCallList(m_id_DL4);
		glDisable(GL_TEXTURE_2D);
		m_back.DrawButton(m_inback, "back.png", buttonsTex_ids[4]);
	}

	
}


bool Screen::ButtonActive(Button button, int mx, int my, bool press)
{
	bool res = false;

	if (press && (button.GetX0()<mx) && (button.GetX1()>mx) && (button.GetY0()<my) && (button.GetY1()>my))
	{
		res = true;
		return res;
	}
	return res;
}


void Screen::SetScreenDraw(int mx, int my, bool pressDown)
{
	m_instart = ButtonActive(m_start, mx, my, pressDown);
	m_incontrols = ButtonActive(m_controls, mx, my, pressDown);
	m_inscores = ButtonActive(m_scores, mx, my, pressDown);
	m_incredits = ButtonActive(m_credits, mx, my, pressDown);
}

void Screen::SetScreenAction(int mx, int my, bool pressUp)

{	
	m_bstart = ButtonActive(m_start, mx, my, pressUp);
	m_bcontrols = ButtonActive(m_controls, mx, my, pressUp);
	m_bscores = ButtonActive(m_scores, mx, my, pressUp);
	m_bcredits = ButtonActive(m_credits, mx, my, pressUp);

}

void Screen::SetBackAction(int mx, int my, bool pressUp)
{
	m_bback = ButtonActive(m_back, mx, my, pressUp);
}
void Screen::SetBackDraw(int mx, int my, bool pressDown)
{
	m_inback = ButtonActive(m_back, mx, my, pressDown);
}

bool Screen::waiting()
{
	return !m_bstart && !m_bcontrols && !m_bscores && !m_bcredits;
}

bool Screen::GetStart()
{
	return m_bstart;
}
bool Screen::GetControls()
{
	return m_bcontrols;
}
bool Screen::GetScores()
{
	return m_bscores;
}
bool Screen::GetCredits()
{
	return m_bcredits;
}
bool Screen::GetBack()
{
	return m_bback;
}
